package com.datamanage.processing.repository;

import com.datamanage.processing.entity.ProcessingTask;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProcessingTaskRepository extends JpaRepository<ProcessingTask, Long> {
    
    @Query("SELECT t FROM ProcessingTask t WHERE t.companyId = :companyId ORDER BY t.createdAt DESC")
    Page<ProcessingTask> findByCompanyId(@Param("companyId") Long companyId, Pageable pageable);
    
    @Query("SELECT t FROM ProcessingTask t WHERE t.companyId = :companyId AND t.createdBy = :userId ORDER BY t.createdAt DESC")
    Page<ProcessingTask> findByCompanyIdAndUserId(@Param("companyId") Long companyId, @Param("userId") Long userId, Pageable pageable);
    
    @Query("SELECT t FROM ProcessingTask t WHERE t.companyId = :companyId AND t.status = :status ORDER BY t.createdAt DESC")
    Page<ProcessingTask> findByCompanyIdAndStatus(@Param("companyId") Long companyId, @Param("status") String status, Pageable pageable);
    
    List<ProcessingTask> findByStatusOrderByCreatedAtAsc(String status);
}